Skip to main content

All Questions

1vote
1answer
54views

Object name undefined using localize script

Iam having problems enqueueing a script with wp_localize_script. I have done this several times before and I cannot see what Iam doing wrong here. I have changed the handle of the script several times ...
LWS-Mo's user avatar
  • 1,591
0votes
0answers
51views

Uncaught ReferenceError: custom_ajax is not defined

I am trying to create an application that will add products to a cart using PHP and JavaScript + Ajax. In order to do so, I have written this script in functions.php: // Enqueue Fetch API script ...
BrigantiumXIX's user avatar
0votes
1answer
316views

localize_script but data changes dependent on product ID

I currently have this code in my functions.php file. $dataToBePassed = array(); add_action( 'wp_enqueue_scripts', function() { $handle = 'three-d-scripts'; $src = ...
sico87's user avatar
2votes
1answer
2kviews

wp_add_inline_script not adding when script_loader_tag filtered

I'm trying to add the new GA4 code to an existing site, and there seems to be some conflict / ordering issue between script_loader_tag filters and wp_add_inline_script. My functions.php looks thusly: ....
philolegein's user avatar
1vote
1answer
258views

Enqueue scripts all over but not in single.php

I need to insert this script in the footer on the home, in categories, in pages, in the tags in the search but NOT in single.php: function live_search() { wp_enqueue_script('live_search', ...
fr0zen's user avatar
3votes
1answer
3kviews

How to add extra attributes to the script tag added via wp_localize_script()

So, wp_localize_script() are awesome to add custom data to a script. And these data gets added to the HTML like: <script id='woocommerce_some-js-extra' type="text/javascript"> var ...
iSaumya's user avatar
0votes
0answers
2kviews

Get with jQuery the value of an ACF field

I'm trying to store in a variable the content of an ACF field so that later on I can use it in a jQuery function using the plugin "Simple Custom CSS and JS". I found what I thought was the ...
Jonattan Salcedo's user avatar
0votes
0answers
493views

Pass post ID to JavaScript outside the loop

I try to pass the post/pages ID to my JavaScript file. url and template_url works but the id just return 0 on every post. PHP: // Register scripts wp_enqueue_script('scripts', ...
Axel Murman's user avatar
0votes
1answer
418views

How to pass data to javascript in custom widget class

I have a custom widget where the user can insert an username in an <input> field. It's working fine, but I need to get the inserted value from php and pass it to the javascript file that is ...
sialfa's user avatar
0votes
2answers
4kviews

Ajax is not defined

Stack Exchange long time listener, first time caller. I have found examples on the developer.wordpress site but I have been still struggling. Localizing scripts: wp_localize_script() In my theme's ...
Daniel Nebert's user avatar
1vote
1answer
2kviews

wp_localize_script not working on ajax response

When a file is uploaded to my page I make an ajax call to add an entry in a database. I then want to send a string back to the client using wp_localize_script but when I try to access it I just get an ...
dreddx's user avatar
0votes
1answer
393views

Ajax Response Error | just getting error as the response

Below is the code for the AJAX File. alert(cont) is given the correct result but the problem is with the response. I am just getting error as the response. function updateRadioButton(rating,pid){ ...
Mohit's user avatar
1vote
1answer
693views

How to enqueue the script without hardcoded in the theme files?

I have been working on the Custom Gallery Layout style and was wondering how do I enqueue and make the following script working without hard coded in the file. Or is there a better way of adding it ...
Maqk's user avatar
  • 398
0votes
1answer
81views

How to make sure, that only the selected post is changing?

So I was able to save the content of each post in an array, thanks to a very good answer on it: How to localize value of posts I just copied the solution here: function register_and_enqueue_script() ...
TheOnionMaster's user avatar
0votes
1answer
369views

How to localize value of posts

I've got a problem again. I scripted a little JS function, that alters content of a post. To pass the content to the function I used this: function register_and_enqueue_script() { ...
TheOnionMaster's user avatar

153050per page
close